// Signal.cpp : Implementation of CSignal
#include "stdafx.h"
#include "GPSstructs.h"
#include "Signal.h"

/////////////////////////////////////////////////////////////////////////////
// CSignal

STDMETHODIMP CSignal::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_ISignal
	};
	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

STDMETHODIMP CSignal::InitalParameters()
{
//	AFX_MANAGE_STATE(AfxGetStaticModuleState())
	

	ATLASSERT(m_pSingnal!=NULL);
	if(m_pSingnal == NULL)
		return S_FALSE;
	// TODO: Add your implementation code here
	m_Title = CComBSTR(m_pSingnal->Title);
	m_xLabel = CComBSTR(m_pSingnal->xLabel);
	m_yLabel = CComBSTR(m_pSingnal->yLabel);
	
	m_minx	= m_pSingnal->minx;
	m_miny	= m_pSingnal->miny;
	m_maxx	= m_pSingnal->maxx;
	m_maxy	= m_pSingnal->maxy;

	m_dataNumber = m_pSingnal->dataNumber;
	m_pDataAddr	= (long)m_pSingnal->data;


	return S_OK;
}

STDMETHODIMP CSignal::test()
{
	// TODO: Add your implementation code here
	
	put_SignalType(ST_SITEX_);

	return S_OK;
}

STDMETHODIMP CSignal::DataFromIndex(int index, double* data)
{
	// TODO: Add your implementation code here
	ATLASSERT(m_pSingnal!=NULL);
	if(m_pSingnal == NULL)
		return S_FALSE;

	if(index <0 || index > m_dataNumber)
		return S_FALSE;

	double * pDouble = (double*)m_pDataAddr;
	if(!pDouble)
		return S_FALSE;

	*data = pDouble[index];
	
	return S_OK;
}
